﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 作 者：曾洋
// 日 期：2012-4-1 16:15:29
// 描 述：联系人信息处理
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using ZX.Web.UI.Controls;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using System.Collections.Generic;
using ZX.SYS.Library;
using ZX.BLL;
using ZX.Web.UI.Controls.ControlBind;
using ZX.DBModule;
using ZX.Common;
using ZX.BLL.Extend;
namespace ZX.WebApp.Crm.MeetingArrange
{
    public partial class AddCrmLiveSale : EditUIPage
    {
        BTCrmCustomer bll = new BTCrmCustomer();
        BDatPhraseDetail bDatPhraseDetail = new BDatPhraseDetail();
        BTCrmCrustomerOrder order = new BTCrmCrustomerOrder();
        string tempProduct = "", tempProductPack = "", strUnitId = "", strListProduct = "", strListOrderProduct="";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    IList<DatPhraseDetail> listPayType = bDatPhraseDetail.GetDatPhraseDetailByClassValue("PaymentID");
                    DropDownListControl.DropDataSourceBind(this.ddlPayType, listPayType, "PhraseText", "PhraseID");
                    string id = this.GetStringFromQueryString("id", "");
                    BaseEntity instance = ZX.Common.Globals.getEntity("CrmLiveOrDerManager") as BaseEntity;
                    BaseBussnies bInstance = new BLL.Extend.BaseBussnies(instance);
                    BaseEntity entity = bInstance.GetEntityById(id) as BaseEntity;
                    this.EditTemplate.Text = CreateInstanceJsObject(instance, entity);
                    //IList<CrmProduct> listProduct = bll.GetAllCrmProduct();
                    //DropDownListControl.DropDataSourceBind(this.ddlProductName, listProduct, "Caption", "Productid");
                    IList<CrmProductPack> listPack = bll.GetAllCrmProductPack();
                    DropDownListControl.DropDataSourceBind(this.ddlProductPack, listPack, "Packname", "ID");
                    //if (listProduct != null && listProduct.Count > 0)
                    //{
                    //    IList<BaseEntity> _listLinkMan = new List<BaseEntity>();
                    //    foreach (var _e in listProduct)
                    //    {
                    //        _listLinkMan.Add(_e);
                    //    }
                    //    tempProduct = _listLinkMan.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
                    //}
                    if (listPack != null && listPack.Count > 0)
                    {
                        IList<BaseEntity> _listLinkMan = new List<BaseEntity>();
                        foreach (var _e in listPack)
                        {
                            _listLinkMan.Add(_e);
                        }
                        tempProductPack = _listLinkMan.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
                    }
                    ID.Value = Guid.NewGuid().ToString();

                    if (StrProductId != "")
                    {
                        if (StrId == "")
                        {
                            AddUser.Value = this.UserId.ToString();
                            AddTime.Value = DateTime.Now.ToString("yyyy-MM-dd");
                        }
                        else
                        {
                            ID.Value = StrId;
                            V_CrmLiveOrDerManager vcod = new V_CrmLiveOrDerManager();
                            vcod = bll.GetLiveSaleInfo(new Guid(StrId));
                            if (vcod != null)
                            {
                                CustomId.Value = vcod.CustomerID.ToString();
                                txtCustomId.Value = vcod.CustomerName;
                                Code.Text = vcod.CustomerCode;
                                CustomerFrom.Text = vcod.OriginName;
                                InformationPro.Text = vcod.AddUserName;
                                FirstTeacher.Text = vcod.LectorName;
                                SaleGw.Text = vcod.SaleadviserName;
                                CMName.Text = vcod.CustomerMgrName;
                                MiddleService.Text = vcod.ClassServerName;
                                Memember.Value = vcod.NegotiateTeachID;
                                txtMemember.Value = vcod.SignName;
                               // SignSaler.Text = vcod.SureName;
                                BelongDepart.Text = vcod.OrderofDeptName;
                               // ddlProductName.SelectedValue = vcod.ProductID.ToString();
                                ddlProductPack.SelectedValue = vcod.ProductPack.ToString(); 
                               // ProductPrice.Text = vcod.Money.ToString();
                              //  Amount.Text = vcod.Amount.ToString();
                              //  AccountReceivable.Text = vcod.AccountReceivable.ToString();
                              //  ResignMoney.Text = vcod.ResignMoney.ToString();
                                TotalMoney.Value = vcod.TotalMoney.ToString();
                                TotalRebate.Value = vcod.TotalRebate.ToString();
                                ddlPayType.SelectedValue = vcod.PayType.ToString();
                                ddlIsInvoice.SelectedItem.Text = vcod.IsInvoice;
                                ShouldMoney.Value = vcod.ResignMoney.ToString();
                                POSNum.Text = vcod.POSNum;
                                InvoiceNum.Text = vcod.InvoiceNum;
                                PactNum.Text = vcod.PactNum;
                                ReceiptNum.Text = vcod.ReceiptNum;
                                CrmDeliverMajorID.Value = vcod.CrmDeliverMajorID.ToString();
                                Explain.Text = vcod.Explain;
                                AddUser.Value = vcod.AddUser.ToString();
                                AddTime.Value = vcod.AddTime.ToString("yyyy-MM-dd");
                            }
                            IList<V_CrmLiveOrderProduct> ListOrderProduct = order.GetAllLiveProduct(new Guid(StrId));
                            if (ListOrderProduct != null && ListOrderProduct.Count > 0)
                            {
                                IList<BaseEntity> _ListOrderProduct = new List<BaseEntity>();
                                foreach (var _e in ListOrderProduct)
                                {
                                    _ListOrderProduct.Add(_e);
                                }
                                strListOrderProduct = _ListOrderProduct.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
                            }
                        }
                    }
                }
                catch (Exception)
                {

                    throw;
                }
            }
            //产品
            IList<V_CrmProduct> ListProduct = order.GetAllCrmCustomerProduct("");
            if (ListProduct != null && ListProduct.Count > 0)
            {
                IList<BaseEntity> _ListProduct = new List<BaseEntity>();
                foreach (var _e in ListProduct)
                {
                    _ListProduct.Add(_e);
                }
                strListProduct = _ListProduct.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
            }
            //单位
            IList<DatPhraseDetail> ListUnitId = bDatPhraseDetail.GetDatPhraseDetailByClassValue("UnitId");
            if (ListUnitId != null && ListUnitId.Count > 0)
            {
                IList<BaseEntity> _ListUnitId = new List<BaseEntity>();
                foreach (var _e in ListUnitId)
                {
                    _ListUnitId.Add(_e);
                }
                strUnitId = _ListUnitId.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
            }
        }


        /// <summary>
        /// 课程ID
        /// </summary>
        public string StrProductId
        {
            get { return this.GetStringFromQueryString("productId", ""); }
        }
        /// <summary>
        /// 现场销售ID
        /// </summary>
        public string StrId
        {
            get { return this.GetStringFromQueryString("id", ""); }
        }
        /// <summary>
        /// 订单产品列表
        /// </summary>
        public string ListOrderProduct
        { get { return strListOrderProduct; } }
        /// <summary>
        /// 产品列表
        /// </summary>
        public string ListCrmProduct
        { get { return strListProduct; } }
        /// <summary>
        /// 计量单位
        /// </summary>
        public string ListUnitId
        { get { return strUnitId; } }
        public string StrProduct
        {
            get { return tempProduct; }
        }
        public string StrProductPack
        {
            get { return tempProductPack; }
        }
    }
}